package com.zdp.chat.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * 响应数据类型
 *
 * @author hf
 */

@AllArgsConstructor
@Getter
public enum WSRespTypeEnum {
    LOGIN_SUCCESS(3, "认证通过", null),
    MESSAGE(4, "新消息", null),
    ONLINE_OFFLINE_NOTIFY(5, "上下线通知", null),
    INVALIDATE_TOKEN(6, "使前端的token失效，意味着前端需要重新登录", null),
    BLACK(7, "拉黑用户", null),
    MARK(8, "消息标记", null),
    RECALL(9, "消息撤回", null),
    SYSTEM(10, "系统消息", null),
    //MEMBER_CHANGE(11, "成员变动", WSMemberChange.class),
    AUTHENTICATION_FAILURE(12, "认证失败", String.class),
    CHANNEL_MODIFY(13, "账号已在别处登录~", String.class),
    ROOM_INFO(14, "房间信息", null),
    HEART_BEAT_CHECK(15, "心跳检查", null)
    ;

    private final Integer type;
    private final String desc;
    private final Class dataClass;

    private static Map<Integer, WSRespTypeEnum> cache;

    static {
        cache = Arrays.stream(WSRespTypeEnum.values()).collect(Collectors.toMap(WSRespTypeEnum::getType, Function.identity()));
    }

    public static WSRespTypeEnum of(Integer type) {
        return cache.get(type);
    }
}
